import $ from 'jquery'
import { global } from '../../filter/global-api'
import { Message } from 'element-ui'
import _common from '../commonJs/wptx_common'
import _tools from '../commonJs/wptx_tools'
import _request from '../../utils/request'
import { Loading } from 'element-ui'
// import { errors } from '../../api/error'
const _FUNCTION_NAME = 'portalapi/sysmanage/dict/'
const _API_NAME = ''
export default {
  configPage: _configPage, // 全部分页
  configList: _configList, // 查询配置列表
  configUpdate: _configUpdate, // 更新
  configflush: _configflush, // 强制刷新版本
  configCreate: _configCreate, // 新增配置项
  configlistGroup: _configlistGroup
}

/* POST /portalapi/sysmanage/dict/config/page 查询配置列表*/
function _configPage(vm, data, callBack) {
  const self = vm
  _tools.info('===【 _configList 】 url: ' + _FUNCTION_NAME + 'config/page')
  _tools.info('===【 _configList 】 Params data:', data)
  const url = _FUNCTION_NAME + 'config/page'
  const params = data
  var loadingInstance = Loading.service({
    text: '加载中'
  })
  _request({
    url: url,
    method: 'post',
    data: params
  }).then((res) => {
    loadingInstance.close()
    _tools.info('API 调用成功，返回 code = 200')
    callBack(res)
  }).catch((error) => {
    loadingInstance.close()
    _tools.info('【 _configList 】 调用异常 ')
    _tools.error(error)
    callBack(null)
  })
}

/* POST  /portalapi/sysmanage/dict/config/listGroup 查询配置组列表*/
function _configlistGroup(vm, data, callBack) {
  const self = vm
  _tools.info('===【 _configList 】 url: ' + _FUNCTION_NAME + 'config/listGroup')
  _tools.info('===【 _configList 】 Params data:', data)
  const url = _FUNCTION_NAME + 'config/listGroup'
  const params = data
  var loadingInstance = Loading.service({
    text: '加载中'
  })
  _request({
    url: url,
    method: 'post',
    data: params
  }).then((res) => {
    loadingInstance.close()
    _tools.info('API 调用成功，返回 code = 200')
    callBack(res)
  }).catch((error) => {
    loadingInstance.close()
    _tools.info('【 _configList 】 调用异常 ')
    _tools.error(error)
    callBack(null)
  })
}

/* POST /csmapi/dict/config/list 查询配置列表*/
function _configList(vm, data, callBack) {
  const self = vm
  _tools.info('===【 _configList 】 url: ' + _FUNCTION_NAME + 'config/list')
  _tools.info('===【 _configList 】 Params data:', data)
  const url = _FUNCTION_NAME + 'config/list'
  const params = data
  var loadingInstance = Loading.service({
    text: '加载中'
  })
  _request({
    url: url,
    method: 'post',
    data: params
  }).then((res) => {
    loadingInstance.close()
    _tools.info('API 调用成功，返回 code = 200')
    callBack(res)
  }).catch((error) => {
    loadingInstance.close()
    _tools.info('【 _configList 】 调用异常 ')
    _tools.error(error)
    callBack(null)
  })
}

/* POST /csmapi/dict/config/update 更新*/
function _configUpdate(vm, data, callBack) {
  const self = vm
  _tools.info('===【 _templateUpdate 】 url: ' + _FUNCTION_NAME + 'config/update')
  _tools.info('===【 _templateUpdate 】 Params data:', data)
  const url = _FUNCTION_NAME + 'config/update'
  const params = data
  var loadingInstance = Loading.service({
    text: '加载中'
  })
  _request({
    url: url,
    method: 'post',
    data: params
  }).then((res) => {
    loadingInstance.close()
    _tools.info('API 调用成功，返回 code = 200')
    callBack(res)
  }).catch((error) => {
    loadingInstance.close()
    _tools.info('【 _templateUpdate 】 调用异常 ')
    _tools.error(error)
    callBack(null)
  })
}

/* POST /csmapi/dict/config/flush 强制刷新版本*/
function _configflush(vm, data, callBack) {
  const self = vm
  _tools.info('===【 _configflush 】 url: ' + _FUNCTION_NAME + 'config/flush')
  _tools.info('===【 _configflush 】 Params data:', data)
  const url = _FUNCTION_NAME + 'config/flush'
  const params = data
  var loadingInstance = Loading.service({
    text: '加载中'
  })
  _request({
    url: url,
    method: 'post',
    data: params
  }).then((res) => {
    loadingInstance.close()
    _tools.info('API 调用成功，返回 code = 200')
    callBack(res)
  }).catch((error) => {
    loadingInstance.close()
    _tools.info('【 _configflush 】 调用异常 ')
    _tools.error(error)
    callBack(null)
  })
}

/* POST /csmapi/dict/config/create 新增配置项*/
function _configCreate(vm, data, callBack) {
  const self = vm
  _tools.info('===【 _configflush 】 url: ' + _FUNCTION_NAME + 'config/create')
  _tools.info('===【 _configflush 】 Params data:', data)
  const url = _FUNCTION_NAME + 'config/create'
  const params = data
  var loadingInstance = Loading.service({
    text: '加载中'
  })
  _request({
    url: url,
    method: 'post',
    data: params
  }).then((res) => {
    loadingInstance.close()
    _tools.info('API 调用成功，返回 code = 200')
    callBack(res)
  }).catch((error) => {
    loadingInstance.close()
    _tools.info('【 _configflush 】 调用异常 ')
    _tools.error(error)
    callBack(null)
  })
}
